<!-- office 表单弹窗 -->
<form id="office-form" lay-filter="office-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">上级机构</label>
            <div class="layui-input-inline">
                <select name="parentId" lay-search>
                    <option></option>
                    <option th:each="office : ${offices}" th:value="${office.id}" th:text="${office.name}"></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">归属区域</label>
            <div class="layui-input-inline">
                <select name="areaId" lay-search>
                    <option></option>
                    <option th:each="area : ${areas}" th:value="${area.id}" th:text="${area.name}"></option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">机构名称<span style="color: red">*</span></label>
            <div class="layui-input-inline">
                <input name="name" placeholder="请输入机构名称" type="text" class="layui-input" maxlength="128"
                       lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">机构编码<span style="color: red">*</span></label>
            <div class="layui-input-inline">
                <input name="code" placeholder="请输入机构编码" type="text" class="layui-input" maxlength="32"
                       lay-verify="required" required/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">机构类型<span style="color: red">*</span></label>
            <div class="layui-input-inline">
                <select name="type" lay-verify="required" required>
                    <option></option>
                    <option value="1">公司</option>
                    <option value="2">部门</option>
                    <option value="3">小组</option>
                    <option value="4">其他</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">机构等级<span style="color: red">*</span></label>
            <div class="layui-input-inline">
                <select name="grade" lay-verify="required" required>
                    <option></option>
                    <option value="1">一级</option>
                    <option value="2">二级</option>
                    <option value="3">三级</option>
                    <option value="4">四级</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">联系地址</label>
            <div class="layui-input-inline">
                <input name="address" placeholder="请输入联系地址" type="text" class="layui-input" maxlength="64"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">邮政编码</label>
            <div class="layui-input-inline">
                <input name="zipCode" placeholder="请输入邮政编码" type="email" class="layui-input" maxlength="32"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
                <input name="phone" placeholder="请输入电话" type="text" class="layui-input" maxlength="24"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">传真</label>
            <div class="layui-input-inline">
                <input name="fax" placeholder="请输入传真" type="text" class="layui-input" maxlength="24"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">排序号</label>
            <div class="layui-input-inline">
                <input name="sort" placeholder="请输入排序号" type="number" class="layui-input"/>
            </div>
        </div>
    </div>
    <!--<div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="comments" placeholder="请输入内容" class="layui-textarea" maxlength="200"></textarea>
        </div>
    </div>-->
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" app-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="office-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;

        form.render('select');

        var url = 'organization/office/add';
        // 回显area数据
        var office = admin.getTempData('t_office');
        form.val('office-form', office);
        if (office && office.id) {
            url = 'organization/office/update';
        }

        // 表单提交事件
        form.on('submit(office-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.success) {
                    layer.msg(data.msg, {icon: 1});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        });
    });
</script>